package org.hxzon.workeasy.pages.file;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.hxzon.workeasy.model.EasyFile;
import org.hxzon.workeasy.pages.base.MyBasePage;
import org.hxzon.workeasy.permissions.FileCRPermissions;
import org.hxzon.workeasy.service.EasyFileService;

public class ViewFile extends MyBasePage {
    @Inject
    private EasyFileService fileSer;
    @Property
    private String id;
    @Property
    private EasyFile file;

    @OnEvent(value = EventConstants.ACTIVATE)
    Object init(String id) {
        new FileCRPermissions().check(null, getVisitor());
        this.id = id;
        return null;
    }

    @SetupRender
    void display() {
        file = fileSer.findById(id);
    }

    @OnEvent(value = EventConstants.PASSIVATE)
    Object onPassivate() {
        return id;
    }

}
